<?php


namespace app\library\traits;


trait Restful
{
    /**
     * restful路由分发
     */
    public function indexAction()
    {
        //进行路由分发
        switch (strtolower($this->getRequest()->getMethod())) {
            case 'get':
            {
                return $this->read();
            }
            case 'put':
            {
                return $this->update();
            }
            case 'post':
            {
                return $this->save();
            }
            case 'delete':
            {
                return $this->delete();
            }
            default:
            {
                return $this->returnJson(1, "success");
            }
        }
    }



    /**
     * 获取单个
     */
    public function read()
    {
       echo 'read';
    }

    /**
     * 更新
     */
    public function update()
    {
        echo 'update';
    }

    /**
     * 保存
     */
    public function save()
    {
        echo "save";
    }

    /**
     * 删除
     */
    public function delete()
    {
        echo "delete";
    }

}